﻿using System.ComponentModel;
using System.Windows;
using Brjnk.Common;
using Brjnk.GpxExplorer.ViewModel;

namespace Brjnk.GpxExplorer.UI
{
    /// <summary>
    /// Interaction logic for CreateWaypointWindow.xaml
    /// </summary>
    public partial class CreateWaypointWindow : Window, INotifyPropertyChanged
    {
        private WaypointVM waypoint;

        public CreateWaypointWindow(WaypointVM waypoint)
        {
            InitializeComponent();

            PointName = waypoint.Source.Name;
            Coordinates = waypoint.Source.Position;
            NewWaypoint = waypoint;
        }

        private GpsCoordinates coordinates;

        public GpsCoordinates Coordinates
        {
            get { return coordinates; }
            set { coordinates = value; OnPropertyChanged("Coordinates"); }
        }

        private string name = "Wpt";

        public string PointName
        {
            get { return name; }
            set { name = value; OnPropertyChanged("PointName"); }
        }

        private WaypointVM newWaypoint;

        public WaypointVM NewWaypoint
        {
            get { return newWaypoint; }
            set { newWaypoint = value; OnPropertyChanged("NewWaypoint"); }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            NewWaypoint.Source.Name = this.PointName;
            NewWaypoint.Source.Position = this.Coordinates;
            this.DialogResult = true;
        }
    }
}